#include <stdio.h>
#define SIZE 100001
// #define N() for(k=0;k<len;++k) fprintf(stderr,"%3d ",a[k]);fprintf(stderr,"-- %3d\n",j)
// #define M() for(k=0;k<n;++k) fprintf(stderr,"%d;",arr[k]);fprintf(stderr,"-- %2d\n",i)

int
do_stuff (int *a, int len)
{
	register int k, j=0;
	int offset=0;
	int x;

	scanf("%d", &x);
	while (j < len) {
		//N();
		*(a + j) = *(a + j + offset);
		if (a[j + offset] % x == 0) {
			++offset;
			--j;
			--len;
		}
		++j;
	}
	return len;
}

int
main (void)
{
	int n, x;
	int arr[SIZE];
	register int i = 0;
	int k;

	freopen("removal.in", "r", stdin);
	freopen("removal.out", "w", stdout);

	scanf("%d", &n);
	while (i < n)
		scanf("%d", &arr[i++]);
	n = do_stuff(arr, n);
	for (i=0; i < n; ++i)
		printf("%d ", arr[i]);
	printf("\n");

	return 0;
}
